<template>
  <div class="app-container">
    <el-button type="primary" plain  size="small" @click="inspectAll" >一键质检</el-button>
    <el-table border :data="detailList" style="width: 100%">
      <el-table-column label="编号" width="50" type="index" align="center" fixed="left"
                       :index="index=>index+1"/>

      <el-table-column prop="goodsName" label="菜品名称" align="center" min-width="180"/>
      <el-table-column prop="plateStatus" label="摆盘是否干净" align="center" width="120">
        <template #default="scope">
          <span v-show="!scope.row.editFlag" :style="{'color': colors(scope.row.plateStatus)}">{{scope.row.plateStatus}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.plateStatus" placeholder="是/否" clearable :style="{width: '100%'}">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="resourceStatus" label="食材是否新鲜" align="center" width="120">
        <template #default="scope">
          <span v-show="!scope.row.editFlag" :style="{'color': colors(scope.row.resourceStatus)}">{{scope.row.resourceStatus}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.resourceStatus" placeholder="是/否" clearable :style="{width: '100%'}">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="maker" label="制作人" align="center" width="180">
        <template #default="scope">
          <span v-show="!scope.row.editFlag">{{scope.row.maker}}</span>
<!--          <el-input v-show="scope.row.editFlag" v-model="scope.row.maker"></el-input>-->
          <el-select v-show="scope.row.editFlag" v-model="scope.row.maker" filterable clearable placeholder="请选择制作人"  >
            <el-option v-for="item in  dict.type.food_inspector" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="创建人" prop="createBy" width="120" align="center"/>
      <el-table-column label="更新人" prop="updateBy" width="120" align="center"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>

<!--      <el-table-column label="操作" align="center" fixed="right" width="140">-->
<!--        <template #default="scope">-->
<!--          <div style="">-->
<!--            <el-button size="small"-->
<!--                       type="text"-->
<!--                       icon="CircleCheck"-->
<!--                       v-show="scope.row.editFlag"-->
<!--                       @click="submit(scope.row, $index)">保存-->
<!--            </el-button>-->
<!--            <el-button size="small"-->
<!--                       type="text"-->
<!--                       icon="CircleClose"-->
<!--                       v-show="scope.row.editFlag"-->
<!--                       @click="cancel(scope.row, $index)">取消-->
<!--            </el-button>-->
<!--            <el-button size="small"-->
<!--                       icon="Edit"-->
<!--                       type="text"-->
<!--                       v-show="!scope.row.editFlag"-->
<!--                       @click="edit(scope.row, $indx)"> 编辑-->
<!--            </el-button>-->
<!--          </div>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
  </div>
</template>


<script>
import {listAll, get, update, normalBatchEdit} from "@/api/examine/goods/normalExamineDetail";
import {buffetBatchEdit} from "@/api/examine/buffet/detail";

export default {
  name: "ExamineNormalDetail",
  dicts: ['food_inspector'],
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: undefined,
      // 遮罩层
      loading: true,
      detailList: [],
      plateStatusOptions: [
        {
            label: "是",
            value: "是"
        },
        {
            label: "否",
            value: "否"
        }
      ],
      // 是否显示弹出层
      open: false
    };
  },
  created() {
    this.id = this.$route.params && this.$route.params.id;
    this.getList();
  },
  methods: {
    colors(status) {
      if (status === "是") {
        return '#2a9c4a'
      } else {
        return '#FF0000'
      }
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listAll({
        examineId: this.id,
      }).then(response => {
        response.rows.map(item=>{
          item.editFlag=true
        })
        this.detailList = response.rows;
        this.loading = false;
      });
    },
    submit: function(row, index) {
      let updateData = {
        id: row.id,
        plateStatus: row.plateStatus,
        resourceStatus: row.resourceStatus,
        maker: row.maker
      }
      update(updateData).then(res => {
        this.$modal.msgSuccess("更新成功");
        row.editFlag = false;
        this.getList();
      })
    },
    cancel: function(row, index) {
      row.editFlag = false;
      this.getList();
    },
    edit: function(row, index) {
      row.editFlag = true;
      this.$set(this.detailList, index, row);
    },
    inspectAll(){
      let postData=[]
      this.detailList.map(item=>{
        let postItem={
          id:item.id,
          plateStatus:'是',
          resourceStatus:'是',
          maker:item.maker
        }
        postData.push(postItem)
      })
      normalBatchEdit(postData).then(res=>{
        this.$message.success('提交成功')
        this.getList()
      })
    }
  }
};
</script>
